package org.apache.http.entity.mime.content;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.james.mime4j.message.BinaryBody;

public class FileBody extends AbstractContentBody
  implements BinaryBody
{
  private final File file;

  public FileBody(File paramFile)
  {
    this(paramFile, "application/octet-stream");
  }

  public FileBody(File paramFile, String paramString)
  {
    super(paramString);
    if (paramFile == null)
      throw new IllegalArgumentException("File may not be null");
    this.file = paramFile;
  }

  public String getCharset()
  {
    return null;
  }

  public long getContentLength()
  {
    return this.file.length();
  }

  public File getFile()
  {
    return this.file;
  }

  public String getFilename()
  {
    return this.file.getName();
  }

  public InputStream getInputStream()
    throws IOException
  {
    return new FileInputStream(this.file);
  }

  public String getTransferEncoding()
  {
    return "binary";
  }

  public void writeTo(OutputStream paramOutputStream, int paramInt)
    throws IOException
  {
    if (paramOutputStream == null)
      throw new IllegalArgumentException("Output stream may not be null");
    FileInputStream localFileInputStream = new FileInputStream(this.file);
    try
    {
    }
    finally
    {
      byte[] arrayOfByte;
      int i;
      localFileInputStream.close();
      throw localObject;
      paramOutputStream.flush();
      localFileInputStream.close();
    }
  }
}